/**
 * Google统计分析工具
 */

import { getSystemCode } from "../../apps/x-site/common/const-value";
import { getCookie } from "x-site-util";

declare let window: any;

let systemCode = getSystemCode();
let uid = getCookie("cxuid");
export default class GaUtil {
  //店铺总览页的 ga 统计
  static addLandingEvent({
    eventAction,
    eventLabel,
    platform,
    eventValue = 1
  }: {
    eventAction: any;
    eventLabel: any;
    platform: string;
    eventValue?: any;
  }) {
    if (process.env.NODE_ENV === "prod" || process.env.NODE_ENV === "gray") {
      window.ga &&
        window.ga("send", "event", {
          eventCategory: "魔方建站落地页-店铺总览",
          eventAction,
          eventLabel,
          eventValue,
          dimension1: systemCode,
          dimension2: platform,
          dimension3: uid ? "A" + uid : ""
        });
    }
  }

  //页面管理页的 ga 统计
  static addPageEvent({
    eventAction,
    eventLabel,
    platform,
    eventValue = 1
  }: {
    eventAction: any;
    eventLabel: any;
    platform: string;
    eventValue?: any;
  }) {
    if (process.env.NODE_ENV === "prod" || process.env.NODE_ENV === "gray") {
      window.ga &&
        window.ga("send", "event", {
          eventCategory: "魔方建站落地页-页面管理",
          eventAction,
          eventLabel,
          eventValue,
          dimension1: systemCode,
          dimension2: platform,
          dimension3: uid ? "A" + uid : ""
        });
    }
  }

  //模板管理页的 ga 统计
  static addTemplateEvent({
    eventAction,
    eventLabel,
    platform,
    eventValue = 1
  }: {
    eventAction: any;
    eventLabel: any;
    platform: string;
    eventValue?: any;
  }) {
    if (process.env.NODE_ENV === "prod" || process.env.NODE_ENV === "gray") {
      window.ga &&
        window.ga("send", "event", {
          eventCategory: "魔方建站落地页-模板管理",
          eventAction,
          eventLabel,
          eventValue,
          dimension1: systemCode,
          dimension2: platform,
          dimension3: uid ? "A" + uid : ""
        });
    }
  }
}
